package com.rp.system.service;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rp.common.utils.RpUtil;
import com.rp.log.annotation.RpLog;
import com.rp.system.dao.UserDao;
import com.rp.system.dao.UserInfoDao;
import com.rp.system.po.User;
import com.rp.system.po.UserInfo;

@Service
@Transactional
public class UserInfoService {

	@Autowired
	private UserDao userDao;
	@Autowired
	private UserInfoDao userInfoDao;
	
	@RpLog(desc="保存用户信息")
	public String saveUserInfo(Map<String, Object> map, String userId){
		
		UserInfo ui = new UserInfo();
		ui.setXb((String)map.get("xb"));
		ui.setNl((String)map.get("nl"));
		ui.setZw((String)map.get("zw"));
		ui.setSj((String)map.get("sj"));
		ui.setYx((String)map.get("yx"));
		ui.setBgdh((String)map.get("bgdh"));
		ui.setCreateDate(RpUtil.getCurrentDatetime());
		
		ui.setUserId(userId);
		
		String newUserInfoId = (String) userInfoDao.save(ui);
		
		User user = userDao.get(userId);
		user.setRealname((String)map.get("realname"));
		user.setRemark((String)map.get("remark"));
		userDao.update(user);
		
		return newUserInfoId;
	}
	
	@RpLog(desc="更新用户信息")
	public void updateUserInfo(Map<String, Object> map, String userId){
		
		UserInfo ui = userInfoDao.get((String)map.get("id"));
		ui.setXb((String)map.get("xb"));
		ui.setNl((String)map.get("nl"));
		ui.setZw((String)map.get("zw"));
		ui.setSj((String)map.get("sj"));
		ui.setYx((String)map.get("yx"));
		ui.setBgdh((String)map.get("bgdh"));
		ui.setUpdateDate(RpUtil.getCurrentDatetime());
		userInfoDao.update(ui);
		
		User user = userDao.get(userId);
		user.setRealname((String)map.get("realname"));
		user.setRemark((String)map.get("remark"));
		userDao.update(user);
		
	}
	
	
	
	public UserInfoDao getUserInfoDao() {
		return userInfoDao;
	}
	
}
